
package com.jvtd.demo.amap;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.amap.api.location.CoordinateConverter;
import com.amap.api.location.DPoint;
import com.jvtd.base.JvtdActivity;
import com.jvtd.demo.R;
import com.jvtd.gd_location.utils.CoordinateConvertUtil;
import com.jvtd.widget.toast.JvtdToast;

public class GdCoordinateConvertActivity extends JvtdActivity implements View.OnClickListener
{
  //构造一个示例坐标，第一个参数是纬度，第二个参数是经度
  private DPoint mPoint = new DPoint(39.911127, 116.433608);
  private CoordinateConvertUtil coordinateConvertUtil;
  private JvtdToast mToast;
  private TextView tvConvertReult;
  private TextView tvCheckReult;

  @Override
  protected void bindView()
  {
    TextView tvTitle = findViewById(R.id.tv_title);
    tvTitle.setText("地图计算工具");
    Toolbar mToolbar = findViewById(R.id.tool_bar);
    setToolbar(mToolbar, true);

    TextView textView = findViewById(R.id.textView);
    textView.setText("示例坐标(经度，纬度)：116.433608,39.911127");
    tvConvertReult = findViewById(R.id.tv_convertResult);
    tvCheckReult = findViewById(R.id.tv_checkResult);
    Button btConvert = findViewById(R.id.bt_covert);
    Button btCheck = findViewById(R.id.bt_check);
    btConvert.setOnClickListener(this);
    btCheck.setOnClickListener(this);
  }

  @Override
  protected void getLayout()
  {
    setContentView(R.layout.activity_gd_coordinate_convert);
  }

  @Override
  protected void initViewAndData()
  {
    coordinateConvertUtil = CoordinateConvertUtil.getInstance(this);
    mToast = new JvtdToast(this, JvtdToast.FLAG_BOTTOM);
  }

  @Override
  public void onClick(View view)
  {
    switch (view.getId())
    {
      case R.id.bt_covert:
        DPoint destPoint = coordinateConvertUtil.convert(CoordinateConverter.CoordType.BAIDU, mPoint);
        if (destPoint == null)
          mToast.showMessage("坐标转换失败", 500);
        else
          tvConvertReult.setText("转换后坐标(经度、纬度):" + destPoint.getLongitude() + "," + destPoint.getLatitude());
        break;

      case R.id.bt_check:
        boolean result = coordinateConvertUtil.checkIsAvaliable(mPoint);
        if (result)
          tvCheckReult.setText("该坐标是高德地图可用坐标");
        else
          tvCheckReult.setText("该坐标不能用于高德地图");
        break;
    }
  }
}
